//
//  TransitioningDelegateManager.m
//  TransitioningDelegateManager
//
//  Created by Apple on 2018/3/21.
//  Copyright © 2018年 LYKM. All rights reserved.
//

#import "TransitioningDelegateManager.h"
#import "TransitioningAnimator.h"

@interface TransitioningDelegateManager ()

/**   */
@property (nonatomic,strong) TransitioningAnimator *animator;

@end

@implementation TransitioningDelegateManager

+ (instancetype)managerWithFromView:(UIView*)fromView toView:(UIView*)toView {
    TransitioningDelegateManager *manager = [[TransitioningDelegateManager alloc] init];
    manager.animator = [[TransitioningAnimator alloc] init];
    manager.animator.fromTargetView = fromView;
    manager.animator.toTargetView = toView;
    return manager;
}

#pragma mark -- UIViewControllerTransitioningDelegate

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    self.animator.transitingType = TransitingTypePresent;
    return self.animator;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    self.animator.transitingType = TransitingTypeDismisss;
    return self.animator;
}

#pragma mark -- UINavigationControllerDelegate
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
    switch (operation) {
        case UINavigationControllerOperationPop:
            self.animator.transitingType = TransitingTypeDismisss;
            return self.animator;
            break;
        case UINavigationControllerOperationPush:
            self.animator.transitingType = TransitingTypePresent;
            return self.animator;
            break;
        default:
            return nil;
            break;
    }
}

@end



